#!/usr/bin/env python
# coding: utf-8

from datetime import datetime

dt_now = datetime.now()  # 当前日期

time_obj = dt_now.time() #22:00:20.727825 <class 'datetime.time'>
print(time_obj, type(time_obj))

month = dt_now.strftime('%m')
print(month) #09

to_dt_str = dt_now.strftime('%Y-%m-%d')
print(to_dt_str) #2017-09-19

to_dt = datetime.strptime(to_dt_str, '%Y-%m-%d')
print(to_dt, type(to_dt))  #2017-09-19 00:00:00 <class 'datetime.datetime'>

start = datetime(2014,12,1)
print(start, type(start))  #2014-12-01 00:00:00 <class 'datetime.datetime'>

end = datetime.now()
print(end, type(end))  #2017-09-19 20:51:50.559316 <class 'datetime.datetime'>

delta = end - start
print(delta, type(delta))   #1023 days, 20:51:50.559316 <class 'datetime.timedelta'>
#
print(delta.days, type(delta.days), delta.seconds, type(delta.seconds)) #1023 <class 'int'> 75110 <class 'int'>

print(start>end, start<end)  #False True